<div class="sm-rightPanel">
    <div id="list_form" class="layui-form sm-operation">
        <blockquote class="site-text layui-elem-quote">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">问卷列表：</label>
                    <div class="layui-input-inline">
                        <select id="paperInfoList" name="paperInfoId" lay-filter="paperInfoList">
                            <option value="">全部</option>
                        </select>
                    </div>
                </div>
                <div class="layui-inline">
                    <button id="query" class="layui-btn"><i class="iconfont icon-sousuo"></i>查询</button>
                </div>
            </div>
        </blockquote>
        <div class="layui-form-item">
            <button class="layui-btn layui-btn-danger" id="role_del">
                <i class="iconfont icon-delete"></i>删除
            </button>
        </div>
    </div>
    <table id="list_table" class="layui-hide" lay-filter="mainList"></table>
</div>
<script>
    layui.use(['layedit','layer', 'table', 'form','layedit'], function () {
        var layedit = layui.layedit;
        var layer = layui.layer;
        var table = layui.table;
        var form = layui.form;
        var $ = layui.$;

        //表单重新渲染
        form.render();


        //表格渲染
        var tableObj = table.render({
            id: 'list_table'
            , elem: '#list_table'
            , url: '/voteapply/getVoteApplyListByPage'
            , align: "center"
            , cols: [[ //表头
                {type: 'checkbox'}
                , {type: 'numbers', title: '序号', width: 50}
                , {field: 'voteName', title: '投票名称', width: 200, align: 'center'}
                , {field: 'nickName', title: '昵称', width: 200, align: 'center'}
                ,{field: 'applyImg', title: '头像', width: 180, align: 'center',templet:function (d) {
                    return "<img class='fans-portrait' src=" + d.applyImg + " />"
                }}
                , {field: 'applyBrief', title: '简介', width: 350, align: 'center'}
                , {field: 'createTime', title: '报名时间', width: 170, align: 'center'}
                , {field: 'totalCount', title: '投票人数', width: 150, align: 'center'}
            ]]
        });


        $("#role_del").click(function () {
            var data = table.checkStatus('list_table').data;
            var arr = [];
            for (var i = 0; i < data.length; i++) {
                arr.push(data[i].id);
            }
            if (data.length == 0) {
                layer.msg("请至少选择一条");
                return;
            }

            smartAui.confirm('确认删除？', function () {
                $.ajax({
                    type: "GET",
                    url: '/voteapply/delete',
                    data: {"id": arr.join(",")},
                    success: function (result) {
                        if (result.success) {
                            layer.msg("删除成功");
                            smartAui.reloadTable(tableObj);
                        } else {
                            layer.msg("删除异常");
                        }
                    },

                })
            }, 0);
        });


        //查询数据
        $('#query').on('click', function () {
            smartAui.reloadTable(tableObj);
        });

        getVoteList();


        // 获取投票列表
        function getVoteList(){

            $.ajax({
                type: 'get',
                url: '/vote/list',
                dataType: 'json',
                success: function (data) {
                    var state = data.success;
                    if (state) {

                        var list = data.data;
                        if (list && list.length > 0) {

                            $.each(list, function (n, value) {
                                var id = value.id;
                                var name = value.name;

                                $("#voteList").append("<option value='" + id + "'>" + name + "</option>");
                            });
                        }

                        // 重新渲染表单
                        renderForm();
                    }
                }
            });
        }

        //重新渲染表单
        function renderForm() {

            layui.use(['form'], function () {
                var form = layui.form;
                //表单重新渲染
                form.render();

                form.render('select');
            });
        }


    });


</script>